package org.pgis.gui;

import javax.swing.JPanel;
import javax.swing.JLabel;

import org.pgis.core.AbstractScenePanel;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class QualityPanel extends JPanel{

	private static final long serialVersionUID = 1L;
	private AbstractScenePanel asp;
	public QualityPanel(AbstractScenePanel asp) {
		this.asp = asp;
		initialize();
	}

	private void initialize() {

		this.setLayout(null);

		JSlider sliderTransparency = new JSlider();
		sliderTransparency.setMajorTickSpacing(2);
		sliderTransparency.setMinorTickSpacing(1);
		sliderTransparency.setSnapToTicks(true);
		sliderTransparency.setPaintLabels(true);
		sliderTransparency.setPaintTicks(true);
		sliderTransparency.setValue((int)(asp.getSim().getImageProperty().getOpacity()));
		sliderTransparency.setMaximum(10);
		sliderTransparency.setBounds(18, 22, 200, 46);
		sliderTransparency.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setOpacity((float)value);
                asp.refresh();
            }
        });
		add(sliderTransparency);

		JSlider sliderSmoothness = new JSlider();
		sliderSmoothness.setMajorTickSpacing(10);
		sliderSmoothness.setMinorTickSpacing(5);
		sliderSmoothness.setValue(asp.getSim().getIteration());
		sliderSmoothness.setPaintTicks(true);
		sliderSmoothness.setPaintLabels(true);
		sliderSmoothness.setBounds(18, 86, 200, 46);
		sliderSmoothness.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setIterations(value);
                asp.refresh();
            }
        });
		add(sliderSmoothness);

		JSlider sliderTriangleQuality = new JSlider();
		sliderTriangleQuality.setMinorTickSpacing(5);
		sliderTriangleQuality.setMajorTickSpacing(10);
		sliderTriangleQuality.setPaintTicks(true);
		sliderTriangleQuality.setPaintLabels(true);
		sliderTriangleQuality.setBounds(18, 148, 200, 46);
		sliderTriangleQuality.setValue(asp.getSim().getTriangleQuality());
		sliderTriangleQuality.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setTriangleQuality(value);
                asp.refresh();
            }
        });
		add(sliderTriangleQuality);

		JLabel labelOpacity = new JLabel("Opacity");
		labelOpacity.setBounds(6, 6, 55, 16);
		add(labelOpacity);

		JLabel labelSmoothness = new JLabel("Smoothness");
		labelSmoothness.setBounds(6, 72, 92, 16);
		add(labelSmoothness);

		JLabel labelTriangleQuality = new JLabel("TriangleQuality");
		labelTriangleQuality.setBounds(6, 135, 118, 16);
		add(labelTriangleQuality);

		/*JSlider sliderIterativQuality = new JSlider();
		sliderIterativQuality.setSnapToTicks(true);
		sliderIterativQuality.setMinorTickSpacing(5);
		sliderIterativQuality.setMajorTickSpacing(10);
		sliderIterativQuality.setValue(0);
		sliderIterativQuality.setPaintTicks(true);
		sliderIterativQuality.setPaintLabels(true);
		sliderIterativQuality.setBounds(18, 218, 200, 39);
		add(sliderIterativQuality);

		JLabel labelIterativeQuality = new JLabel("Iterative Quality");
		labelIterativeQuality.setBounds(6, 202, 92, 16);
		add(labelIterativeQuality);*/
	}
}
